package edu.pku.sei.transformation.editor.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.PlatformUI;

import edu.pku.sei.transformation.editor.model.Compatiable;
import edu.pku.sei.transformation.editor.model.MetaModel;
import edu.pku.sei.transformation.util.MetaModelSubsetChecker;

public class CheckCompatibilibyAction extends Action {
	Compatiable compatiable;

	public CheckCompatibilibyAction(Compatiable c) {
		compatiable = c;
		this.setText("Check Compatibility");
	}

	@Override
	public void run() {
		Object compatibleModel = compatiable.getSource().getType();
		Object baseModel = compatiable.getTarget().getType();
		if (compatibleModel instanceof MetaModel
				&& baseModel instanceof MetaModel) {
			MetaModelSubsetChecker checker = new MetaModelSubsetChecker(
					(MetaModel) baseModel, (MetaModel) compatibleModel);
			if (checker.check())
				MessageDialog.openInformation(PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getShell(),
						"check compatibility", "check successful");
			else
				MessageDialog.openError(PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow().getShell(),
						"check compatibility", "check failed");
		}
	}
}
